﻿// Extensão do jQuery para obter capacidades do cliente
(function($) {
    if (typeof $.browser === "undefined" || !$.browser) {
        var browser = {};
        $.extend(browser);
    }
    var pluginList = {
        flash: {
            activex: "ShockwaveFlash.ShockwaveFlash",
            plugin: /flash/gim
        },
        sl: {
            activex: ["AgControl.AgControl"],
            plugin: /silverlight/gim
        },
        qtime: {
            activex: "QuickTime.QuickTime",
            plugin: /quicktime/gim
        },
        wmp: {
            activex: "WMPlayer.OCX",
            plugin: /(windows\smedia)|(Microsoft)/gim
        },
        shk: {
            activex: "SWCtl.SWCtl",
            plugin: /shockwave/gim
        },
        rp: {
            activex: "RealPlayer",
            plugin: /realplayer/gim
        },
        svg: {
            activex: "Adobe.SVGCtl",
            plugin: /adobe\s?acrobat/gim
        }
    };
    var isSupported = function(p) {
        if (window.ActiveXObject) {
            try {
                new ActiveXObject(pluginList[p].activex);
                $.browser[p] = 1;
            } catch (e) {
                $.browser[p] = 0;
            }
        } else {
            $.each(navigator.plugins, function() {
                if (this.name.match(pluginList[p].plugin)) {
                    $.browser[p] = 1;
                    return false;
                } else {
                    $.browser[p] = 0;
                }
            });
        }
    };

    $.each(pluginList, function(i, n) {
        isSupported(i);
    });

})(jQuery);

jQuery.extend(jQuery.browser, {
    cookie: (function() {
        var tmpcookie = new Date();
        chkcookie = (tmpcookie.getTime() + '');
        document.cookie = "chkcookie=" + chkcookie + "; path=/";
        if (document.cookie.indexOf(chkcookie, 0) < 0) {
            return 0;
        } else {
            return 1;
        }
    })(),
    name: (function() {
        if (jQuery.browser.safari)
            return "safari";
        if (jQuery.browser.opera)
            return "opera";
        if (jQuery.browser.msie)
            return "msie";
        if (jQuery.browser.mozilla)
            return "mozilla";
    })(),
    size: (function() {
        return screen.width + 'x' + screen.height;
    })(),
    asize: (function() {
        return screen.availWidth + 'x' + screen.availHeight;
    })(),
    color: (function() {
        return screen.colorDepth;
    })(),
    pdf: (function() {
        var activex = "PDF.PdfCtrl";
        var activex7 = "acroPDF.PDF";
        var plugin = "/adobe\s?acrobat/gim";
        if (window.ActiveXObject) {
            try {
                new ActiveXObject(activex);
                return 1;
            } catch (e) {
                try {
                    new ActiveXObject(activex7);
                    return 1;
                } catch (e) {
                    return 0;
                }
            }
        } else {
            var found=0;
			$.each(navigator.plugins, function () {
				if (this.name.match(plugin)) {
					found = 1;
					return false;
				}
			});
			return found;
        }        
    })(),
    java:  (function() {
            if (navigator.javaEnabled()){
                return 1;
            }else{
                return 0;
            }
    })(),
    pagesize: (function() {
        var pagebytes = $('html').html().length;
        var kbytes = pagebytes / 1024;
        return kbytes;
    })()
});

//Funções auxiliares
function _void() { return; }

//Tratamento do evento load para montar a requisição a imagem dummy
$(document).ready(function() {
    var _o = new Array();
    var _n = new Array();
    _o[0] = jQuery.browser.cookie; _n[0] = 'cookie';
    _o[1] = jQuery.browser.version; _n[1] = 'version';
    _o[2] = jQuery.browser.name; _n[2] = 'name';
    _o[3] = jQuery.browser.flash; _n[3] = 'flash';
    _o[4] = jQuery.browser.pdf; _n[4] = 'pdf';
    _o[5] = jQuery.browser.sl; _n[5] = 'sl';
    _o[6] = jQuery.browser.qtime; _n[6] = 'qtime';
    _o[7] = jQuery.browser.wmp; _n[7] = 'wmp';
    _o[8] = jQuery.browser.shk; _n[8] = 'shk';
    _o[9] = jQuery.browser.rp; _n[9] = 'rp';
    _o[10] = jQuery.browser.java; _n[10] = 'java';
    _o[11] = jQuery.browser.size; _n[11] = 'size';
    _o[12] = jQuery.browser.asize; _n[12] = 'asize';
    _o[13] = jQuery.browser.color; _n[13] = 'color';
    _o[14] = jQuery.browser.pagesize; _n[14] = 'pagesize';

    var _ugifpath2 = baseUrl + "App_Themes/InfraWebTheme/images/__stat.gif";
    var i2 = new Image(1, 1);
    var params = "";
    for (var i = 0; i < _o.length; i++) {
        params = params + _n[i] + "=" + _o[i] + "&";
    }
    i2.src = _ugifpath2 + "?" + params.substring(0, params.length - 1);
    i2.onload = function() { _void(); }
});